package com.wutuo.common;

import cn.apestar.user.api.enums.UserType;
import cn.apestar.user.provider.info.domain.User;
import cn.apestar.user.provider.institution.dao.UserAndInstituionMapper;
import cn.apestar.user.provider.institution.enums.AuditStateEnum;
import cn.apestar.user.provider.institution.request.UserAndInstituionRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Singer_YDW on 2016/11/10.
 */
@Service("UserAndInstitutionWTService") public class UserAndInstitutionWTService {

    @Autowired
    private UserAndInstituionMapper userAndInstituionMapper;

    /**
     * 获取机构的人员
     *
     * @return List<UserAndInstituionResponse>
     * @author lvh 2016年3月26日 下午4:53:00</br>
     */
    public Map getUserListByUserId(Long cmInstitutionId) {

        // 校长
        List listMaster = new ArrayList();
        // 老师
        List listTeacher = new ArrayList();

        UserAndInstituionRequest request = new UserAndInstituionRequest();
        request.setState(AuditStateEnum.TG_TG.getLongValue());
        request.setCmInstitutionId(cmInstitutionId);
        request.setDelFlag(true);
        List<User> userAndInstituionList = userAndInstituionMapper.listUser(request);
        for (int i = 0; i < userAndInstituionList.size(); i++) {
            User o = userAndInstituionList.get(i);
            if (UserType.MASTER.getValue().equals(o.getUserType())) {
                listMaster.add(o);
            } else if (UserType.TEACHER.getValue().equals(o.getUserType())) {
                listTeacher.add(o);
            }
        }
        Map mapResult = new HashMap();
        mapResult.put("listMaster", listMaster);
        mapResult.put("listTeacher", listTeacher);
        return mapResult;
    }
}
